class ViewController < ApplicationController

  def set_scheme
    session[:scheme]=params[:scheme_name]
    redirect_to :controller=>"view", :action=>"index"
  end

  def list
    @photos = Photo.find :all, :order=>"position DESC"
    @albums = Album.find :all
  end

  def album
    @albums = Album.find :all
    @album = Album.find params[:id]
    @photos = @album.photos
    render :action=>"list"
  end

  def show_albums
    @i = 0
    @k = 0
    @l = 0
    @str=""
    @width_f = 0
    @photos1 = Array.new
    @albums = Album.find :all

    for album in @albums
     @photos1[@i]=album.photos[0]
     @i+=1
    end
    @i=0
    @photos = Photo.find :all
    render :action=>"show_albums"
   end

  def show_scetch
    @i = 0
    @k = 0
    @width_f = 0
    @album = Album.find params[:id]
    @photos = @album.photos
    @photos1 = Array.new
    render :action=>'show_scetch'
  end

  def show_diafilm
    @i = 0
    @k = 0
    @al
    @width_f = 0
    @albums = Album.find :all
    @photo  = Photo.find(params[:id])
    @photos1 = Array.new

    for alb in @albums
      if alb.photos.include?(@photo)
        album = alb
      end
    end
    @al = album
    @photos = album.photos

    while @k <= @photos.size do
      if  (@photos[@k]==@photo)
        @num_ph = @k
      end
      @k+=1
    end
    @k=0
    render :action=> "show_diafilm"
  end

  def tag
    if params[:photo]!=nil
      @i = 1
      @k = 0
      @al
      @width_f = 0
       @tag = Tag.find_by_id(params[:id])
      @photos=Array.new
      @photos=Tag.get_photos(@tag.title)
      @num_ph=Integer(params[:photo])
      @albums = Album.find :all
      for alb in @albums
        if alb.photos.include?(@photos[@num_ph])
          album = alb
        end
      end
    @al = album
      render :action=>'tags_diafilm'
    else
      @tag = Tag.find_by_id(params[:id])
      @photos=Array.new
      @photos=Tag.get_photos(@tag.title)
      render :action=>'tags_scetch'
    end
  end
  
  def tags
    @tags=Array.new
    @tags=Tag.find :all, :order=>"title"
    @tags_sizes = Array.new
    @tags.each do |t|
      @tags_sizes<<t.photos.size
    end
    @max=@tags_sizes.max
    @min=@tags_sizes.min
    @range=Settings.get_cloud_range
    @tags_links=Array.new
    @tags.each do |t|
      if (@max-@min)!=0 
         @tags_links<<"<font style='font-size:"+String(12+(Tag.get_tag_weight(t.title)-@min)*Integer(@range)/(@max-@min))+"px;'>"+t.title+"</font>"
      else
         @tags_links<<"<font style='font-size:12px;'>"+t.title+"</font>"
      end
    end
    render :action=>'tags'
  end

end